//
//  WMRequestBase.m
//  WholeMusic
//
//  Created by quanxiong on 2018/3/4.
//  Copyright © 2018年 quanxiong. All rights reserved.
//

#import "WMRequestBase.h"

@interface WMRequestBase ()
@property (strong, nonatomic, readwrite) NSMutableDictionary *urlToSessionManager;
@end

@implementation WMRequestBase

- (instancetype)init {
    if (self = [super init]) {
        _urlToSessionManager = [NSMutableDictionary dictionary];
    }
    return self;
}

- (AFHTTPSessionManager *)managerForBaseURL:(NSString *)url {
    if (url.length == 0) {
        return nil;
    }
    AFHTTPSessionManager *manager = self.urlToSessionManager[url];
    if (!manager) {
        NSURL *baseURL = [NSURL URLWithString:url];
        manager = [[AFHTTPSessionManager alloc]initWithBaseURL:baseURL];
        manager.operationQueue.maxConcurrentOperationCount = 1;
        manager.requestSerializer.HTTPShouldHandleCookies = YES;
        manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:
                                                             @"application/x-javascript",
                                                             @"application/json",
                                                             @"text/json",
                                                             @"text/javascript",
                                                             @"text/plain",
                                                             @"text/html", nil];
        self.urlToSessionManager[url] = manager;
    }
    return manager;
}

@end
